<template>
  <div
    class="section-category"
    :class="{ isBlue: options.colorStyle === 'blue' }"
    :style="{
      background: options.backgroundColor
    }"
  >
    <div class="main">
      <ul class="left-btn">
        <li
          v-for="(btn, index) in showData"
          :key="btn.id"
          :class="['btn-item', { active: index === showIndex }]"
          :style="`height:${itemHeight}px;line-height:${itemHeight}px`"
          @click="handleChange(index)"
          :title="btn.categoryTitle"
        >
          <span v-if="btn.categoryTitle" :class="['vportal', iconList[index]]"></span>
          <span class="section">{{ btn.categoryTitle }}</span>
        </li>
      </ul>
      <ul class="show-section image-view cover">
        <a
          v-if="showCategory.link"
          class="photo"
          :title="showCategory.title"
          :href="`${newsBasePath}${showCategory.link}`"
          target="_blank"
        >
          <ShowImg :key="showCategory.categoryId" :item="showCategory" />
        </a>
        <div class="show-news">
          <li v-for="(show, index) in showContent" :key="index" class="show-item">
            <div class="title">
              <Tag v-if="show.extText" :value="show.extText[0][0]" style="display: inline-block" />
              <a :href="`${newsBasePath}${show.link}`" target="_blank">{{ show.subject }}</a>
            </div>
            <div class="zw">
              <span>{{ show.brief }}</span>
            </div>
            <div class="foot" v-if="rowList.includes('publishDate')">
              <div class="part-one">
                <span class="time">{{ show.createDate }}</span>
                <!-- <span class="read">阅读量：{{ show.viewNum }}</span> -->
              </div>
              <!-- <div class="part-two">
                                <span class="comment">
                                    <span class="vp-common"></span>
                                    {{ show.commentNum }}</span
                                >
                                <span class="like">
                                    <span class="vp-common"></span>
                                    {{ show.praiseNum }}
                                </span>
                            </div> -->
            </div>
          </li>
        </div>
      </ul>
    </div>
  </div>
</template>

<script>
  import Tag from '../../news/components/tag.vue';
  import { rowList } from '@/mixins';
  import { methods } from '@/utils';
  export default {
    name: 'SectionCategory',
    components: {
      Tag
    },
    mixins: [rowList],
    props: {
      list: {
        type: Array
      },
      categoryList: {
        type: Array
      },
      // contentWidth: {},
      options: {
        type: Object
      }
    },
    data() {
      return {
        imgBasePath,

        // 展示按钮的icon
        iconList: [
          'vp-news-classification1',
          'vp-news-classification2',
          'vp-news-classification3',
          'vp-news-classification4'
        ],
        showIndex: 0,
        // 正在展示哪个版块的内容
        showCategory: this.categoryList[0],
        // 展示的内容
        showContent: [],
        newsBasePath: `${_basePath}/`,
        contentHeight: methods.getContentHeight(this.sectionData.options),
        itemHeight: 0
      };
    },
    computed: {
      showData() {
        const arr = this.categoryList.slice();
        if (arr.length < 4) {
          for (let i = arr.length; i < 4; i++) {
            arr.push({});
          }
        }
        return arr;
      }
    },
    created() {
      this.itemHeight = this.contentHeight / 4 - 2;
      this.initShowContent(this.showCategory);
    },
    methods: {
      /**
       * @decoration 切换版块显示
       */
      handleChange(index) {
        // console.log(index);
        if (!this.showData[index].categoryTitle) return;
        this.showIndex = index;
        this.showCategory = this.showData[index];
        this.initShowContent(this.showCategory);
        // this.showData.forEach((item,ind)=>{
        //     item.isCurrent = false;

        // })
        // console.log(this.showCategoryTitle);
      },
      /**
       * @description:初始化展示数据,
       * @param {val} 当前展示的板块",
       * @return 展示的数组,
       */
      initShowContent({ categoryTitle }) {
        this.showContent = this.list.filter((item) => {
          if (item.categoryLabel == categoryTitle) {
            return item;
          }
        });

        this.showContent =
          this.showContent.length > 2 ? this.showContent.slice(0, 2) : this.showContent;
      }
    }
  };
</script>

<style lang="scss" scoped>
  $red: #d43e2a;
  $blue: #288def;

  * {
    padding: 0;
    margin: 0;
    text-decoration: none;
    list-style: none;
    box-sizing: border-box;
  }

  .section-category {
    width: 100%;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    background-color: #fff;
    border: 1px solid $red;
    // border: 1px solid #e0e0e0;

    &::-webkit-scrollbar {
      /* 滚动条整体部分，其中的属性有width,height,background,border等（就和一个块级元素一样）（位置1） */
      width: 4px;
      height: 4px;
    }

    &::-webkit-scrollbar-button {
      /* 滚动条两端的按钮（位置2） */
      display: none;
    }

    &::-webkit-scrollbar-track-piece {
      /* 内层轨道，滚动条中间部分（位置4） */
      width: 8px;
      background-color: #f5f5f5;
      border-radius: 6px;
    }

    &::-webkit-scrollbar-thumb {
      /* 滚动条里面可以拖动的那部分（位置5） */
      height: 50px;
      cursor: pointer;
      background: #bec7d5;
      border-radius: 6px;
    }

    &.isBlue {
      border-color: $blue;

      .left-btn {
        color: $blue;

        .btn-item {
          &.active {
            background-color: $blue;
          }
        }
      }
    }
  }

  .main {
    // min-width: 900px;
    position: relative;
    height: 100%;
    min-width: 846px;
  }

  .left-btn {
    position: relative;
    z-index: 10;
    width: 180px;
    height: 100%;
    //   border: 1px solid #e0e0e0;
    color: $red;
    background-color: #fff;
    border-right: 1px solid;

    > li:first-child ~ li {
      border-top: 1px solid;
    }

    .btn-item {
      // background-color: #fff;
      width: 100%;
      height: 70px;
      padding-right: 20px;
      padding-left: 30px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      cursor: pointer;

      .vportal {
        margin-right: 5px;
      }

      &.active {
        color: #fff;
        background-color: $red;
      }
    }
  }

  .show-section {
    position: absolute;
    top: 0;
    right: 0;
    left: 190px;
    height: 100%;
    padding: 10px;
    background-color: #fff;

    .photo {
      float: left;
      width: 340px;
      height: inherit;

      // img {
      //   width: 100%;
      //   height: 100%;
      // }
    }

    .show-news {
      margin-left: 350px;

      .show-item {
        position: relative;
        height: 130px;
        padding-top: 10px;
        // color: #000;
        border-bottom: 1px solid #ccc;

        .title {
          width: 100%;
          height: 30px;
          overflow: hidden;
          font-weight: bold;
          text-overflow: ellipsis;
          white-space: nowrap;

          a {
            display: inline;
            color: #000;
          }
        }

        .zw {
          display: -webkit-box;
          width: 100%;
          max-height: 32px;
          overflow: hidden;
          line-height: 16px;
          text-overflow: ellipsis;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2; /* 想省略几行就写几 */
          > span {
            margin-top: 10px;
            font-size: 14px;
            color: #999;
          }
        }

        > .foot {
          position: absolute;
          bottom: 10px;
          width: 100%;
          font-size: 14px;
          color: #999;

          > div {
            display: inline-block;
          }

          .part-one {
            .time {
              margin-right: 10px;
            }
          }

          // .part-two {
          //     float: right;
          // }
        }
      }
    }

    > a {
      display: block;
    }
  }

  .blue-active {
    color: #fff !important;
    background-color: $blue;
  }

  .red-active {
    color: #fff !important;
    background-color: $red;
  }
</style>
